package com.rede.didiok.user.modulelist.rank.restapi;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.rede.didiok.common.annotion.log.BussinessLog;
import com.rede.didiok.common.constant.conf.SysConf;
import com.rede.didiok.common.dto.rank.RankDto;
import com.rede.didiok.common.enums.BehaviorEnum;
import com.rede.didiok.common.utils.ResultUtil;
import com.rede.didiok.common.utils.StringUtils;
import com.rede.didiok.user.modulelist.rank.service.MemberGradeService;
import com.rede.didiok.user.modulelist.rank.service.RankMemberService;
import com.rede.didiok.user.modulelist.rank.service.RankService;

/**
 * 榜单RestApi
 *
 * @author Rede
 * @date 2019年11月26日18:59:21
 */
@RestController
@RequestMapping("/rank")
@Api(value = "榜单相关接口", tags = {"榜单相关接口"})
@Slf4j
public class RankRestApi {

    @Autowired
    RankService rankService;
    @Autowired
    MemberGradeService memberGradeService;
    @Autowired
    RankMemberService rankMemberService;

    /**
     * 获取榜单的信息
     */
    @ApiOperation(value = "获取榜单的信息", notes = "获取榜单的信息")
    @GetMapping("/getRankList")
    public String getRankList() {
        log.info("获取榜单的信息");
        return ResultUtil.result(SysConf.SUCCESS, rankService.getList());
    }

    @BussinessLog(value = "点击榜单", behavior = BehaviorEnum.VISIT_CLASSIFY)
    @ApiOperation(value = "通过 rankUid 获取榜单成员", notes = "\"通过 rankUid 获取榜单成员")
    @GetMapping("/getRankMemberByRankUid")
    public String getRankMemberByRankUid(@ApiParam(name = "rankUid", value = "榜单UID", required = false) @RequestParam(name = "rankUid", required = false) String rankUid,
                                          @ApiParam(name = "currentPage", value = "当前页数", required = false) @RequestParam(name = "currentPage", required = false, defaultValue = "1") Long currentPage,
                                          @ApiParam(name = "pageSize", value = "每页显示数目", required = false) @RequestParam(name = "pageSize", required = false, defaultValue = "10") Long pageSize) {

        if (StringUtils.isEmpty(rankUid)) {
            log.info("点击榜单,传入 rankUid 不能为空");
            return ResultUtil.errorWithMessage("传入 rankUid 不能为空");
        }
        log.info("通过 rankUid 获取榜单列表");
        return ResultUtil.result(SysConf.SUCCESS, rankMemberService.getListByRankUid(rankUid, currentPage, pageSize));
    }

    /**
     * 查询媒资分类列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "获取媒资分类列表", notes = "获取媒资分类列表", response = String.class)
    @PostMapping("/list")
    public String list(RankDto rankDto) {
        return ResultUtil.successWithData(rankService.getPageList(rankDto));
    }


    /**
     * 获取媒资分类详细信息
     */
    @ApiOperation(value = "获取媒资分类详细信息", notes = "获取媒资分类详细信息", response = String.class)
    @GetMapping(value = "/{uid}")
    public String getInfo(@PathVariable("uid") String uid) {
        return ResultUtil.successWithData(rankService.getById(uid));
    }
}

